package logic

import (
	"book/bookrpc/bookrpcclient"
	"context"

	"book/api/internal/svc"
	"book/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookUpdateLogic {
	return &BookUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookUpdateLogic) BookUpdate(req *types.BookUpdateRequest) (resp *types.Response, err error) {
	data, err := l.svcCtx.BookRpc.BookUpdate(l.ctx, &bookrpcclient.BookUpdateRequest{
		UserId:    req.UserId,
		ClassName: req.ClassName,
		Title:     req.Title,
		Image:     req.Title,
		Context:   req.Context,
		BookId:    req.BookId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改成功",
		Data:    data,
	}, nil
}
